import Mock from 'mockjs';

// 上传文件
Mock.mock('/api/v1/trend/upload', 'post', () => {
  return {
    code: 200,
    data: {
      fileId: Mock.Random.guid(),
      fileName: Mock.Random.word(5, 10) + '.pdf',
      fileSize: Mock.Random.natural(1000, 1000000),
      uploadTime: Mock.Random.datetime(),
      status: 'pending'
    },
    message: '上传成功'
  };
});

// 获取文件列表
Mock.mock(/\/api\/v1\/trend\/files(\?.+)?$/, 'get', (options: { url: string }) => {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const page = parseInt(params.get('page') || '1');
  const pageSize = parseInt(params.get('pageSize') || '20');

  const list = Mock.mock({
    'list|5-10': [{
      'fileId': '@guid',
      'fileName': '@word(5,10).pdf',
      'fileSize': '@natural(1000, 1000000)',
      'uploadTime': '@datetime',
      'status|1': ['pending', 'processing', 'completed', 'failed'],
      'description': '@sentence(3,6)'
    }]
  });

  return {
    code: 200,
    data: {
      total: list.list.length,
      list: list.list
    },
    message: 'success'
  };
});

// 执行趋势分析
Mock.mock('/api/v1/trend/analyze', 'post', () => {
  return {
    code: 200,
    data: {
      analysisId: Mock.Random.guid(),
      status: 'processing',
      progress: 0
    },
    message: 'success'
  };
});

// 获取分析结果
Mock.mock(/\/api\/v1\/trend\/result\/.*/, 'get', (options: { url: string }) => {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const analysisId = params.get('analysisId');

  return {
    code: 200,
    data: {
      analysisId: Mock.Random.guid(),
      status: 'completed',
      progress: 100,
      result: {
        timeline: Mock.mock({
          'timeline|5': [{
            'time': '@date',
            'keywords|3': [{
              'word': '@word(3,6)',
              'frequency': '@natural(1, 100)',
              'trend': '@float(-1, 1, 2)'
            }]
          }]
        }).timeline,
        hotwords: Mock.mock({
          'hotwords|10': [{
            'word': '@word(3,6)',
            'count': '@natural(50, 1000)',
            'documents|2': [{
              'fileId': '@guid',
              'fileName': '@word(5,10).pdf',
              'snippet': '@paragraph(1)'
            }]
          }]
        }).hotwords
      }
    },
    message: 'success'
  };
});

// 导出报告
Mock.mock(/\/api\/v1\/trend\/export\/.*/, 'post', (options: { url: string }) => {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const analysisId = params.get('analysisId');

  return {
    code: 200,
    data: {
      url: Mock.Random.url('http')
    },
    message: 'success'
  };
});